
import * as echarts from '../../ec-canvas/echarts';
// 出液月对比图表
function initChart1(canvas, width, height) {
  wx.request({
    url: 'https://server.ifufan.com/Index/Liquid/get_liquid_count_month',
    method:"POST",
    data:{
      userid:wx.getStorageSync('userid'),
      type:'1',
    },
    success:(res)=>{
      console.log(res,"出液日对比")
      let day = res.data.data
      let arrday = []
      for(let i = 0 ; i < day.length;i++){
        arrday.push(day[i].num)
      }
      let arrmonth=[]
      for(let i = 0 ; i < day.length;i++){
        arrmonth.push(day[i].month)
      }

        const chart = echarts.init(canvas, null, {
          width: width,
          height: height
        });
        canvas.setChart(chart);
      var option1 = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {            // 坐标轴指示器，坐标轴触发有效
              type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
      },
      grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
      },
        xAxis :{
          type:'category',
          data:arrmonth,
          axisLabel:{
            interval:0,
            textStyle:{
              fontSize: '16',		//字体大小
                //字体加粗
            }
          }
        },
        yAxis:{
          type:'value'
        },
        series:[{
          data:arrday,
          type:'bar',
          color:'rgb(0,193,163)',
          barWidth:'20%',

        }]
      };
        chart.setOption(option1);
        return chart;
  
    }
  })
  }

// 出液月对比图表
function initChart3(canvas, width, height) {
  wx.request({
    url: 'https://server.ifufan.com/Index/Liquid/get_liquid_count_month',
    method:"POST",
    data:{
      userid:wx.getStorageSync('userid'),
      type:'2',
    },
    success:(res)=>{
      console.log(res.data.data,"出液日对比=====")
      let day = res.data.data
      let arrday = []
      for(let i = 0 ; i < day.length;i++){
        arrday.push(day[i].num)
      }
      let arrmonth=[]
      for(let i = 0 ; i < day.length;i++){
        arrmonth.push(day[i].month)
      }

        const chart = echarts.init(canvas, null, {
          width: width,
          height: height
        });
        canvas.setChart(chart);
      var option3 = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {            // 坐标轴指示器，坐标轴触发有效
              type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
      },
      grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
      },
        xAxis :{
          type:'category',
          data:arrmonth,
          axisLabel:{
            interval:0,
            textStyle:{
              fontSize: '16',		//字体大小
                //字体加粗
            }
          }
        },
        yAxis:{
          type:'value'
        },
        series:[{
          data:arrday,
          type:'bar',
          color:'rgb(0,193,163)',
          barWidth:'20%',

        }]
      };
        chart.setOption(option3);
        return chart;
    }
  })
  }




// 日出液对比
function initChart2(canvas, width, height) {
wx.request({
  url: 'https://server.ifufan.com/Index/Liquid/get_liquid_count_day',
  method:"POST",
  data:{
    userid:wx.getStorageSync('userid'),
    type:'1',
  },
  success:(res)=>{
    console.log(res,"日出液数据")
    let dat= res.data.data
    let arr=[]
    for(let i=0;i<dat.length;i++){
      arr.push(dat[i].num)
    }
    let arrweek=[]
    for(let i=0;i<dat.length;i++){
      arrweek.push(dat[i].day)
    }
    console.log(arr,arrweek,"chuye")
      const chart = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      canvas.setChart(chart);
    var option2 = {
      tooltip: {
        trigger: 'axis',
        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
      xAxis :{
        type:'category',
        data:arrweek,
        axisLabel:{
          interval:0,
          textStyle:{
            fontSize: '16',		//字体大小
            	//字体加粗
          }
        }

      },
      yAxis:{
        type:'value'
      },
      series:[{
        data:arr,
        type:'bar',
        color:'rgb(0,193,163)',
        barWidth:'20%'
      }]
    };
      chart.setOption(option2);
      return chart;

  }
})
}

//日入夜对比
function initChart4(canvas, width, height) {
  wx.request({
    url: 'https://server.ifufan.com/Index/Liquid/get_liquid_count_day',
    method:"POST",
    data:{
      userid:wx.getStorageSync('userid'),
      type:'2',
    },
    success:(res)=>{
      let dat= res.data.data
      let arr=[]
      for(let i=0;i<dat.length;i++){
        arr.push(dat[i].num)
      }
      let arrweek=[]
      for(let i=0;i<dat.length;i++){
        arrweek.push(dat[i].day)
      }
      console.log(arr,arrweek,"chuye")
        const chart = echarts.init(canvas, null, {
          width: width,
          height: height
        });
        canvas.setChart(chart);
      var option4 = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {            // 坐标轴指示器，坐标轴触发有效
              type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
      },
      grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
      },
        xAxis :{
          type:'category',
          data:arrweek,
          axisLabel:{
            interval:0,
            textStyle:{
              fontSize: '16',		//字体大小
            }
          }
        },
        yAxis:{
          type:'value'
        },
        series:[{
          data:arr,
          type:'bar',
          color:'rgb(0,193,163)',
          barWidth:'20%'
        }]
      };
        chart.setOption(option4);
        return chart;
  
    }
  })
  }


// pages/mygogo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    option1: [
      { text: '2021年8月', value: 0 },
     
    ],
    value1: 0,
    // 入夜
    ec:{
      onInit: initChart1
    },
    ec2:{
      onInit: initChart3
    },
    // 出液
    ex:{
      onInit: initChart2
    },
    ex2:{
      onInit: initChart4
    },
    // 出液
    in_num:'',
    out_num:'',
    list:[],
  // 入液
    list2:[],

    mingxigai:1,
    mingxiye:'chuye',
    yuexiye:'chuye',
    rixiye:'chuye',
    shijian:''
  },
  gogogo(){
    wx.redirectTo({
      url: '/pages/liquidlog/index',
    })
  },
  gotongji(){
    wx.redirectTo({
      url: '/pages/mygogo/mygogo',
    })
  },
  goindex(){
    wx.redirectTo({
      url: '/pages/mymy/mymy',
    })
  },
  // 详情
  xiangqing(){
      wx.request({
        url: 'https://server.ifufan.com/Index/Liquid/get_liquid_count_month_list',
        method:"POST",
        data:{
          userid:wx.getStorageSync('userid'),
          type:'1',
          month:"2021-08"
        },
        success:(res)=>{
          this.setData({
            in_num:res.data.in_num,
            out_num:res.data.out_num,
            list:res.data.data
          })
        }
      })
      wx.request({
        url: 'https://server.ifufan.com/Index/Liquid/get_liquid_count_month_list',
        method:"POST",
        data:{
          userid:wx.getStorageSync('userid'),
          type:'2',
          month:"2021-08"
        },
        success:(res)=>{
          this.setData({
            list2:res.data.data
          })
        }
      })
    
  },
  
  // 每日对比
  riduibi(){
    wx.request({
      url: 'https://server.ifufan.com/Index/Liquid/get_liquid_count_day',
      method:"POST",
      data:{
        userid:wx.getStorageSync('userid'),
        type:'1',
      },
      success:(res)=>{
        console.log(res,"信息")
      }
    })
  },
// 月对比
  yueduibi(){
    wx.request({
      url: 'https://server.ifufan.com/Index/Liquid/get_liquid_count_month',
      method:"POST",
      data:{
        userid:wx.getStorageSync('userid'),
        type:'1',
      },
      success:(res)=>{
        console.log(res,"信息")
        
      }
    })
  },


  // 明细切换
  yeti(e){
    this.setData({
      mingxiye:e.currentTarget.dataset.index
    })
  },
// 月对比切换
yueyeti(e){
  this.setData({
    yuexiye:e.currentTarget.dataset.index
  })
},

// 日对比切换
riyeti(e){
    this.setData({
      rixiye:e.currentTarget.dataset.index
    })
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // shijian
    console.log(new Date().toLocaleDateString().slice(0,4),"时间")
    console.log(new Date().toLocaleDateString().slice(5,6),"时间")
    console.log(new Date().toLocaleDateString().slice(7,10),"时间")
    this.setData({
        shijian: new Date().getFullYear()+ '年'+ new Date().getMonth() + '月' +  new Date().getDate()+ '日',
    })
    console.log(this.data.shijian,"时间")
this.xiangqing()
this.riduibi()
// this.yueduibi()



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})